﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace TopShooter.Editor
{
	public class Brush
	{
		public int Diameter = 1;

		public Brush()
		{
		}

		public IEnumerable<Coordinate> GetCoverage(Point screenLoc, Scene scene)
		{
			if ((Diameter % 2) == 1)
			{	// It's Odd...
				int radius = (Diameter - 1) / 2;

				for (int x = -radius; x <= radius; x++)
				{

					for (int y = -radius; y <= radius; y++)
					{
						Vector2 absLoc = new Vector2(screenLoc.X + scene.VportOffset.X, screenLoc.Y + scene.VportOffset.Y);
						Coordinate center = Coordinate.FromLocation(absLoc);
						Coordinate loc = new Coordinate(center.Column + x, center.Row + y);
						yield return loc;
					}
				}
			}
			else
			{	// It's even sized... so find the best four center blocks
				int radius1 = (Diameter / 2) - 1;
				int radius2 = radius1 + 1;

				for (int x = -radius1; x <= radius2; x++)
				{

					for (int y = -radius1; y <= radius2; y++)
					{
						Vector2 absLoc = new Vector2(screenLoc.X + scene.VportOffset.X - Tile.HalfSize.X, screenLoc.Y + scene.VportOffset.Y - Tile.HalfSize.Y);
						Coordinate center = Coordinate.FromLocation(absLoc);
						Coordinate loc = new Coordinate(center.Column + x, center.Row + y);
						yield return loc;
					}
				}
			}
		}
	}
}
